/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package controller;

import camera.ColorMeanCamera;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import utilities.CoordinateFinder;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -Controls the two cameras
 */
public class ColorMeanControllerOld extends Thread {

    final int CAM_NUM1,CAM_NUM2;
    CoordinateFinder coFind=new CoordinateFinder();
    // CanvasFrame canvas = new CanvasFrame("Web Cam Live");
    CanvasFrame path = new CanvasFrame("Position");
    JPanel jp = new JPanel();

    {
        path.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        path.setContentPane(jp);
    }

    public ColorMeanControllerOld(int CAM_NUM1, int CAM_NUM2) {
        this.CAM_NUM1 = CAM_NUM1;
        this.CAM_NUM2 = CAM_NUM2;
    }

    @Override
    public void run() {

        // Initialize Cameras
        ColorMeanCamera cam1 = new ColorMeanCamera(CAM_NUM1,40);
        Thread th = new Thread(cam1);
        th.start();

        ColorMeanCamera cam2 = new ColorMeanCamera(CAM_NUM2,40);
        Thread th1 = new Thread(cam2);
        th1.start();

        int[] ty;
        double theta, beeta, gamma, delta;
        try {
            Thread.sleep(7000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        while (true) {
            // System.out.println("Running");
            theta = cam2.getTheta();
            beeta = cam1.getTheta();
            gamma = Math.toRadians(40) - theta;
            delta = Math.toRadians(40) - beeta;

            // Still case 1 is assumed
            ty = coFind.getCoordinate(1, gamma, beeta);
            paint(ty[0], ty[1]);

        }
    }

    private void paint(int posX, int posY) {
        Graphics g = jp.getGraphics();
        if (posX == -10 || posY == -10) {
            return;// Invalid

        }
        // System.out.println(jp==null);
        // System.out.println(g==null);
        path.setSize(1000, 600);
        g.setColor(Color.RED);
        g.fillOval(1000 - posX, posY, 10, 10);
        //System.out.println(posX + " , " + posY);

    }
}

